﻿using System.Collections.Generic;
using System.Data;

namespace DotNetDAL.Entity
{
    /// <summary>
    /// 分页数据
    /// </summary>
    public class PagingData
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int pagenumber { get; set; }
        /// <summary>
        /// 每页大小
        /// </summary>
        public int pagesize { get; set; }
        /// <summary>
        /// 总数据条数
        /// </summary>
        public int total { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public DataTable rows { get; set; }



        /// <summary>
        /// 转换为字典列表
        /// </summary>
        /// <returns></returns>
        public PagingDictionaryList ToPagingDictionaryList()
        {
            PagingDictionaryList pdl = new PagingDictionaryList();
            pdl.pagenumber = pagenumber;
            pdl.pagesize = pagesize;
            pdl.total = total;

            List<Dictionary<string, object>> table = new List<Dictionary<string, object>>();
            foreach (DataRow dr in rows.Rows)
            {
                Dictionary<string, object> row = new Dictionary<string, object>();
                foreach (DataColumn dc in rows.Columns)
                {
                    row[dc.ColumnName] = dr[dc.ColumnName];
                }
                table.Add(row);
            }
            pdl.rows = table;

            return pdl;

        }


    }

    /// <summary>
    /// 分页数据（泛型）
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    public class PagingData<T> where T : class
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int pagenumber { get; set; }
        /// <summary>
        /// 每页大小
        /// </summary>
        public int pagesize { get; set; }
        /// <summary>
        /// 总数据条数
        /// </summary>
        public int total { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public List<T> rows { get; set; }

    }


    /// <summary>
    ///  分页字典数据
    /// </summary>
    public class PagingDictionaryList
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int pagenumber { get; set; }
        /// <summary>
        /// 每页大小
        /// </summary>
        public int pagesize { get; set; }
        /// <summary>
        /// 总数据条数
        /// </summary>
        public int total { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public List<Dictionary<string, object>> rows { get; set; }


        public PagingDictionaryList() { }
        public PagingDictionaryList(int pagenumber, int pagesize, int total)
        {
            this.pagenumber = pagenumber;
            this.pagesize = pagesize;
            this.total = total;

        }
        public PagingDictionaryList(int pagenumber, int pagesize, int total, List<Dictionary<string, object>> rows)
        {
            this.pagenumber = pagenumber;
            this.pagesize = pagesize;
            this.total = total;
            this.rows = rows;

        }
    }


}
